﻿ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:controls="clr-namespace:Framework.UI.Controls"
                     xmlns:params="http://schemas.codeplex.com/elysium/params">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Converter.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/FocusVisualStyle.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Validation.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/ComboBox.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/DataGrid.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/TextBox.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/ToggleButton.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type controls:ComboDataGrid}">
        <Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.DefaultThickness), Mode=OneWay}"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.ContentFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
        <Setter Property="params:General.ShadowBrush" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.SemiBoldPadding), Mode=OneWay}"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ComboDataGrid}">
                    <Decorator x:Name="LayoutRoot">
                        <controls:BorderFix Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:ComboBox.ButtonSize), Converter={StaticResource DoubleToGridLengthConverter}}"/>
                                </Grid.ColumnDefinitions>
                                <Popup x:Name="PART_Popup" 
                                       Grid.Column="0"
                                       Grid.ColumnSpan="2"
                                       AllowsTransparency="True"
                                       IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
                                       PlacementTarget="{Binding ElementName=LayoutRoot}"
                                       Placement="Custom"
                                       VerticalOffset="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter='Bottom'}"
                                       CustomPopupPlacementCallback="{x:Static params:DropDown.PopupPlacementCallback}"
                                       PopupAnimation="{StaticResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                                       Tag="{StaticResource {x:Static SystemParameters.ComboBoxAnimationKey}}">
                                    <Popup.Resources>
                                        <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource {x:Type ScrollBar}}">
                                            <Style.Triggers>
                                                <Trigger Property="Orientation" Value="Vertical">
                                                    <Setter Property="BorderThickness" Value="0"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Popup.Resources>
                                    <controls:BorderFix x:Name="PopupRoot"
                                            Background="{StaticResource BackgroundBrush}"
                                            BorderBrush="{TemplateBinding BorderBrush}" 
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                                            TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                                            RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                                            MinWidth="{Binding ElementName=LayoutRoot, Path=ActualWidth}"
                                            MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                            Tag="{StaticResource {x:Static SystemParameters.DropShadowKey}}">
                                        <DataGrid x:Name="PART_DataGrid"
                                                  KeyboardNavigation.DirectionalNavigation="Contained"
                                                  Background="{StaticResource BackgroundBrush}"
                                                  BorderThickness="0"
                                                  Focusable="False"
                                                  ItemsSource="{TemplateBinding ItemsSource}"
                                                  SelectedItem="{Binding Mode=TwoWay, Path=SelectedItem, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                  SelectionMode="Single"/>
                                    </controls:BorderFix>
                                </Popup>
                                <ToggleButton x:Name="Button"
                                              Grid.Column="0"
                                              Grid.ColumnSpan="2"
                                              IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
                                              Style="{StaticResource ComboBoxToggleButton}"/>
                                <ContentPresenter x:Name="ContentPresenter"
                                                  Grid.Column="0"
                                                  Content="{TemplateBinding SelectionBoxItem}"
                                                  ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                                                  ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                                  TextBlock.Foreground="{TemplateBinding Foreground}"
                                                  TextBlock.FontSize="{TemplateBinding FontSize}"
                                                  TextBlock.FontStretch="{TemplateBinding FontStretch}"
                                                  TextBlock.FontStyle="{TemplateBinding FontStyle}"
                                                  TextBlock.FontWeight="{TemplateBinding FontWeight}"
                                                  TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                                                  TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                                                  RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                                                  IsHitTestVisible="False"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  Visibility="Visible"/>
                                <Grid x:Name="TextBoxLayout"
                                      Grid.Column="0"
                                      Background="{StaticResource BackgroundBrush}"
                                      Visibility="Collapsed">
                                    <TextBox x:Name="PART_EditableTextBox"
                                             Foreground="{TemplateBinding Foreground}"
                                             FontFamily="{TemplateBinding FontFamily}"
                                             FontSize="{TemplateBinding FontSize}"
                                             FontStretch="{TemplateBinding FontStretch}"
                                             FontStyle="{TemplateBinding FontStyle}"
                                             FontWeight="{TemplateBinding FontWeight}"
                                             IsReadOnly="{TemplateBinding IsReadOnly}"
                                             Margin="{TemplateBinding Padding}"
                                             Style="{StaticResource ComboBoxTextBox}"/>
                                </Grid>
                            </Grid>
                        </controls:BorderFix>
                    </Decorator>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEditable" Value="True">
                            <Setter TargetName="Button" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="Button" Property="Grid.ColumnSpan" Value="1"/>
                            <Setter TargetName="ContentPresenter" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="TextBoxLayout" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger SourceName="PART_Popup" Property="Tag" Value="False">
                            <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
                        </Trigger>
                        <Trigger Property="IsDropDownOpen" Value="True">
                            <Setter TargetName="PART_Popup" Property="params:DropDown.IsOpen" Value="True"/>
                        </Trigger>
                        <!--<MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True"/>
                                <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="True"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="DropDownScrollViewer" Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Mode=OneWay, Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Right, Bottom'}"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True"/>
                                <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="False"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="DropDownScrollViewer" Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Mode=OneWay, Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Top, Right'}"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>-->
                        <!--<MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True"/>
                                <Condition Binding="{Binding ElementName=PART_Popup, Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="PopupRoot" Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                                          BlurRadius="4" ShadowDepth="2"
                                                          Direction="315"
                                                          Opacity="0.3"/>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="PopupRoot" Property="Background" Value="{StaticResource TransparentBrush}"/>
                                <Setter TargetName="PopupRoot" Property="Padding" Value="0,0,6,6"/>
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>-->
                        <!--<MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True"/>
                                <Condition Binding="{Binding ElementName=PART_Popup, Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="PopupRoot" Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                                          BlurRadius="4" ShadowDepth="0"
                                                          Direction="45"
                                                          Opacity="0.3"/>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="PopupRoot" Property="Background" Value="{StaticResource TransparentBrush}"/>
                                <Setter TargetName="PopupRoot" Property="Padding" Value="0,4,4,0"/>
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="True">
                <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource HighlightBrush}"/>
                <Setter Property="BorderBrush" Value="{StaticResource AccentBrush}" />
            </Trigger>
            <Trigger Property="IsDropDownOpen" Value="True">
                <Setter Property="Background" Value="{StaticResource HighlightBrush}"/>
            </Trigger>
            <Trigger Property="Validation.HasError" Value="True">
                <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationErrorControlTemplate}"/>
                <Setter Property="Background" Value="{StaticResource ValidationErrorBrush}"/>
                <Setter Property="ToolTip" Value="{StaticResource ValidationErrorToolTip}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
     
</ResourceDictionary>